Project 2:YouTubeAPI
What: The YouTube APIs * Where: YouTube APIs and Tools * Who: Pratyus Patnaik & Matt Martin = Overview = The YouTube API allows developers to leverage the infrastructure developed by YouTube for storing, playing, and otherwise manipulating video playback over the web. Applications do not have to bother about efficient search mechanisms, video storage or video formats. Using YouTube’s infrastructure, application developers can easily fetch or upload videos and create dynamic playlists. The API is available in the Java, .NET, PHP and Python languages which allows developers to get started quickly in the language of their choice. In general, the API vastly simplifies the task of enriching applications with video content. The suite has four components: * Widgets: Simple embeddable page elements to give sites YouTube functionality. * Custom Player: Allows easy configuring of the custom player to show playlists, videos, etc. * Player APIs: To control over YouTube video playback on the site. * Data API: To perform video searches, upload videos, create playlists, and more. We begin by discussing the simplest components of the YouTube API. The video bar and video search widgets are extremely simple to use, but offer limited customizability. Next we discuss the player API, which offers a simple but powerful way to control video playback within a browser. Then we discuss the data management features offered by the Data API. We go deeper to understand operations which are more relevant from the perspective of a third party application, namely retrieval and manipulation of videos. Finally, we conclude our report by discussing about application using YouTube API and critiquing the API. = API = Widgets “Widgets” offer the most basic level of functionality and customizability within the YouTube API suite. There are two basic widgets, the video bar and the video search control, and both of them can be created and maintained through simple copy and paste of Javascript code snippets. The strength of these widgets is clearly in their simplicity, but the simplicity comes at a cost of customizability. Within these simple widgets, there are only a handful of basic options which can be controlled by the developer. In the video bar API, the developer can specify the orientation of the bar, the size of the video thumbnails, and the location of the associated player. The developer can choose between displaying 4 videos and displaying 8 videos, but there are no other options. Although the thumbnails are displayed in a table, there is no way to change the layout from 1 column to 2 columns, for example. Both of these options would seem relatively straightforward to implement within the API, but neither exists. Additionally, the video bar API offers limited interaction with more advanced YouTube APIs. For example, a slightly more advanced developer may want to combine the video bar with the player API in such a way that videos clicked in the video bar are loaded into a customized YouTube player. Currently, there does not appear to be any simple way to integrate these two APIs. The lack of integration between these two components may be a result of their different development paths. In particular, the video bar and video search widgets seem to have grown out of Google’s AJAX search APIs rather than YouTube-specific APIs. Regardless, developers seeking a more customized functionality cannot rely on reusing either widget within a more complicated application. Player API The Player API offers two main advantages: 1) customized controls and 2) integration with the Data API. At a high level, the player API works by creating a swfobject to store a YouTube player and all of the associated methods. Once this object has been created, videos can be loaded dynamically and playback controls can be embedded anywhere in the page using calls to Javascript methods associated with the swfobject. In particular, one could use links, buttons, or various eventListeners to call the appropriate method. The player API also gives the developer the ability to respond to state changes within the player, such as when the video has completed loaded or if an error occurred during playback. Integration with the Data API leverages the ability to dynamically load videos within the Player API. Thus, queries could be passed to the Data API and the results could be used to generate a dynamic playlist, for example. To generate a dynamic playlist, the developer could pass the first video ID to the loadVideoByID() method and wait for the state change indicating the video has been loaded before calling the playVideo() method. Finally, the developer could repeat the process once the state changes in the player to indicate that playback of the first video has stopped. Data API The YouTube Data API allows users to retrieve and manipulate YouTube videos on their site. It allows applications to perform most of the functions executed on the YouTube website. The API enables applications to search for YouTube videos and retrieve standard video feeds, comments and video responses and ratings. In addition, the API lets applications upload videos to YouTube and delete or update existing videos. Applications can also retrieve and manipulate playlists, subscriptions and user profiles. Usage of Data API Here we will dive deeper into the Data API understanding its usage. To get started one needs to sign up for a developer account. That will give the developer id required to use the API. All the videos uploaded to YouTube using the application can be categorized with the developer id, giving application developers a view of the portion of YouTube uploaded by users using their application. ClientID and associated developer key can be generated from http://code.google.com/apis/base/signup.html. All of the YouTube API calls get handled by YouTubeService object, instantiated with clientID and developer_key (for both authenticated and un-authenticated way), as shown below: YouTubeService service = new YouTubeService(clientID, developer_key); With this call, the user is enabling applications to access the Google server providing services to the API (http://gdata.youtube.com) on his behalf. Authentication All public feeds (search, read-only) do not require any authentication. On the other hand, operations like retrieval of private feeds as well as write, upload, update and delete operations need user authentication. There are two ways to authenticate requests: * AuthSub proxy authentication: It authenticates a user through Google login page. After the user logs in, the application is allowed to use the API to access a user’s account. Google will then redirect the user back to a URL specified in the authentication request. Sessions tokens are maintained for multiple authentications. For Web applications AuthSub authentication is used. * ClientLogin username/password authentication: It is used in installed applications that store the user's email address (username) and password (passed to YouTube using HTTPS). The following code demonstrates how to use ClientLogin to authenticate a user. YouTubeService service = new YouTubeService(clientID, developer_key); service.setUserCredentials("GmailID@gmail.com", "password"); Video Retrieval Data API consists of many video feeds which contains a number of VideoEntry objects. Each video entry corresponds to exactly one URL for a feed of information about a particular video. The information includes information like author, video Id, description, keywords, location, rating, view count, duration, etc. The URL has the following format: http://gdata.youtube.com/feeds/api/videos/videoID The following code retrieves a VideoEntry object, which corresponds to a particular YouTube video, and then prints the metadata for the video: String videoEntryUrl = "http://gdata.youtube.com/feeds/api/videos/videoID"; VideoEntry videoEntry = service.getEntry(new URL(videoEntryUrl), VideoEntry.class); printVideoEntry(videoEntry, TRUE); Also, the API provides feeds selected based on a variety of criteria like region, category. The URL for a region and category feed has the following format: http://gdata.youtube.com/feeds/api/standardfeeds/localeID/feedID_CATEGORY_NAME * localeID are region ids like US for USA and JP for Japan. * feedID are most_viewed, top_rated, recently_featured, etc. * CATEGORY_NAME are Comedy, News etc. The API allows for searching videos based on particular search term. Search can be performed on author name, keywords, formats and full text search on title, metadata, tags. To execute a search request, a YouTubeQuery object is created that specifies search criteria. The following code demonstrates how to perform a search query for videos: YouTubeQuery query = new YouTubeQuery(new URL("http://gdata.youtube.com/feeds/api/videos")); query.setFullTextQuery("Keyword"); VideoFeed videoFeed = service.query(query, VideoFeed.class); Search results can be ordered by RELEVANCE, VIEW_COUNT, UPDATED,''or ''RATING. The information returned is enough to display a video on the site using the Player API. The following code demonstrates how to play a particular video: